﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using PsychSurvey.Properties;

namespace PsychSurvey.Download
{
    public partial class ExportData : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnDownload_Click(object sender, EventArgs e)
        {

            Study myStudy = Study.GetStudy(new Guid(Request.QueryString["StudyId"]));
#if (DEBUG)
            string FileName = myStudy.CreateExcelDocument(Server, Settings.Default.ApplicationRoot_local);
#else
            string FileName = myStudy.CreateExcelDocument(Server,Settings.Default.ApplicationRoot);
#endif

            Response.ContentType = "application/vnd.ms-excel";
            Response.AppendHeader("Content-Disposition", "attachment; filename=Data.xlsx");
            //Response.TransmitFile(Server.MapPath(FileName)); 
            Response.TransmitFile(FileName);
            Response.End();
            myStudy.RemoveExcelDocument(FileName);
        }
    }
}
